package mathcad.matrice;

import Jama.Matrix;
import com.Ostermiller.util.CSVParser;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

public class Polynome64 {

    private double[][] M;
    private double[] V;
    private Matrix[] coeff;

    private Polynome64() throws FileNotFoundException, IOException {
        M = new double[ 6 ][ 6 ];
        V = new double[ 6 ];
        String[] matlines = RWFile.readTextFromFile("/home/me/Desktop/Librairies/matrixpolyn.csv");
        String[] vectlines = RWFile.readTextFromFile("/home/me/Desktop/Librairies/vecteurpolyn.csv");
        String[][] lineparse;
        for (int C = 0 ; C < matlines.length ; C++) {
            for (int L = 0 ; L < matlines.length ; L++) {
                lineparse = CSVParser.parse(matlines[L]);
                M[C][L] = Double.valueOf(lineparse[0][C]);
            }
        }
        for (int L = 0 ; L < matlines.length ; L++) {
            lineparse = CSVParser.parse(vectlines[L]);
            V[L] = Double.valueOf(lineparse[0][0]);
//            System.out.println(V[L]);
        }
        int[] r = new int[ 6 ];


        Matrix Mat, Vect;
        coeff = new Matrix[ 65 ];
        int num = 0;
//        for (int r0 = 1 ; r0 <= 2 ; r0++) {
//            for (int r1 = 1 ; r1 <= 2 ; r1++) {
//                for (int r2 = 1 ; r2 <= 2 ; r2++) {
//                    for (int r3 = 1 ; r3 <= 2 ; r3++) {
//                        for (int r4 = 1 ; r4 <= 2 ; r4++) {
//                            for (int r5 = 1 ; r5 <= 2 ; r5++) {
//                                r[0] = r0;
//                                r[1] = r1;
//                                r[2] = r2;
//                                r[3] = r3;
//                                r[4] = r4;
//                                r[5] = r5;
//                                num++;
//                                Mat = new Matrix(M);
//                                Vect = new Matrix(V, 6);
//                                for (int C = 0 ; C < matlines.length ; C++) {
//                                    for (int L = 0 ; L < matlines.length ; L++) {
//                                        Mat.set(C, L, Mat.get(C, L) * Math.pow(r[L], C));
//                                    }
//                                }
//                                for (int L = 0 ; L < matlines.length ; L++) {
//                                    Vect.set(L, 0, Vect.get(L, 0) * r[L]);
//                                }
//                                coeff[num] = Mat.solve(Vect);
//                            }
//                        }
//
//                    }
//                }
//            }
//        }

        //r=111111
        r[0] = 1;
        r[1] = 1;
        r[2] = 1;
        r[3] = 1;
        r[4] = 1;
        r[5] = 1;
        Mat = new Matrix(M);
        Vect = new Matrix(V, 6);
//        for (int C = 0 ; C < matlines.length ; C++) {
//            for (int L = 0 ; L < matlines.length ; L++) {
//                Mat.set(C, L, Mat.get(C, L) );
//            }
//        }
//        for (int L = 0 ; L < matlines.length ; L++) {
//            Vect.set(L, 0, Vect.get(L, 0) );
//        }
        coeff[0] = Mat.solve(Vect);
        System.out.println(this);
    }

    @Override
    public String toString() {
        super.toString();
        String ret = "";
        double[] tab;
//        for (int num = 0 ; num < M.length ; num++) {
        tab = coeff[0].getRowPackedCopy();
        for (int L = 0 ; L < tab.length ; L++) {
            ret += tab[L] + " , ";
        }
        ret += "\n";
//        }
        return ret;
    }

    public static void main(String[] args) throws FileNotFoundException, IOException {
        new Polynome64();
    }
}
//    @Override
//    public String toString() {
//        super.toString();
//        String ret = "";
//        for (int num = 0 ; num < M.length ; num++) {
//            for (int L = 0 ; L < M.length ; L++) {
//                ret += M[L][num] + " , ";
//            }
//            ret += "\n";
//        }
//        return ret;
//    }

